<template>
  <div>
    <div style="margin-top: 5px; margin-bottom: 5px">
      <el-input v-model="name" placeholder="请输入名字" style="width: 200px" @keyup.enter="loadPost"
        ><template><el-icon class="el-input__icon"></el-icon></template
      ></el-input>
      <el-select v-model="sex" placeholder="请选择性别" style="width: 240px; margin: 5px">
        <el-option v-for="item in sexs" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-button type="primary" style="margin-left: 10px" @click="loadPost">查询</el-button>
      <el-button type="success" @click="resetParam">重置</el-button>
    </div>
    <el-table
      :data="tableData"
      style="height: 100"
      :header-cell-style="{ background: '#f2f5fc', color: '#555', textAlign: 'center' }"
      :cell-style="{ textAlign: 'center' }"
      highlight-current-row
      @current-change="selectCurrentChange"
      border
      stripe
    >
      <el-table-column prop="id" label="ID" width="60" align="center" />
      <el-table-column prop="account" label="账号" width="100" align="center" />
      <el-table-column prop="name" label="姓名" width="100" align="center" />
      <el-table-column prop="age" label="年龄" width="80" align="center" />
      <el-table-column prop="sex" label="性别" width="80" align="center">
        <template v-slot="scope">
          <el-tag :type="scope.row.sex === 1 ? 'primary' : 'success'" disable-transitions>{{
            scope.row.sex == 1 ? '男' : '女'
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="roleId" label="角色" width="120">
        <template v-slot="scope">
          <el-tag
            :type="
              scope.row.roleId === 0 ? 'danger' : scope.row.roleId === 1 ? 'warning' : 'success'
            "
            disable-transitions
            >{{
              scope.row.roleId == 0 ? '超级管理员' : scope.row.roleId === 1 ? '管理员' : '用户'
            }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column prop="phone" label="电话" width="180" />
    </el-table>
    <div class="demo-pagination-block">
      <el-pagination
        v-model:current-page="pageNum"
        v-model:page-size="pageSize"
        :page-sizes="[5, 10, 20, 30]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="text-align: center; margin-top: 20px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { ElMessageBox } from 'element-plus';
import { reactive } from 'vue';
export default {
  name: 'SelectUser',
  data() {
    return {
      tableData: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      name: '',
      sexs: [
        {
          value: '1',
          label: '男',
        },
        {
          value: '0',
          label: '女',
        },
      ],
      readonly: true,
      sex: '',
      dialogVisible: false,
    };
  },
  methods: {
    selectCurrentChange(val) {
      this.$emit('doSelectUser', val);
    },
    loadPost() {
      this.$axios
        .post(this.$httpUrl + '/user/listPageF', {
          pageSize: this.pageSize,
          pageNum: this.pageNum,
          param: {
            name: this.name,
            sex: this.sex,
            roleId: '2',
          },
        })
        .then((res) => res.data)
        .then((res) => {
          console.log(res.data);
          if (res.code == 200) {
            this.tableData = res.data;
            this.total = res.total;
          } else {
            alert('获取数据失败');
          }
        });
    },
    handleSizeChange(val) {
      this.pageNum = 1;
      this.pageSize = val;
      this.loadPost();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.loadPost();
    },
    resetParam() {
      (this.name = ''), (this.sex = '');
      this.loadPost();
    },
    handleClose() {
      ElMessageBox.confirm('你确定要关闭吗?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.dialogVisible = false;
        })
        .catch(() => {});
    },
  },
  created() {
    // this.loadGet();
    this.loadPost();
  },
};
</script>

<style scoped></style>
